#import "CityUIView.h"
#import "StringUtil.h"
#import "ListItem.h"
#import "HttpRequestParamEnginner.h"
@implementation CCityUIView
@synthesize iViewType;
@synthesize iLucktyType;
@synthesize iDataSource;
@synthesize iDelegate;

- (id)initWithFrame:(CGRect)frame;
{
	if(self=[super initWithFrame:frame])
	{
		listView=[[UIListView alloc]initWithFrame:frame];
		[self addSubview:listView];
		[self requestHttp];
		return self;
	}
	return self;
}

-(void)setDataSource:(id <UITableViewDataSource>)aDataSource
{
	listView.dataSource=aDataSource;
}
-(void)setDelegate:(id <UITableViewDelegate>)aDelegate
{
	listView.delegate=aDelegate;
}
-(void)requestHttp
{
	CHttpCommucationEngineer *httpEngineer=[CHttpCommucationEngineer GetIntance];
	CHttpRequestParamEnginner *enginner=[CHttpRequestParamEnginner GetIntance];
	NSString *url=[@"http://soft.luckty.com/Place/getShiXml?id=" stringByAppendingString:enginner->iTempParam.iProvinceId];
	iConnection=[httpEngineer HttpRequest:url tag_Method:HTTP_GET tag_Data:nil tag_ControlId:self tag_Flag:0 tag_Pos:0];
}

-(void)HttpTextResponse:(HttpTextResponseData*)data
{
	int length;
	unsigned char *xmlString;
	length=data->length;
	xmlString=data->data;
	[self ParserXml:xmlString];
	free(xmlString);
}
-(void)ParserXml:(unsigned char *)xmlString
{
	TiXmlDocument *doc=new TiXmlDocument;
	doc->Parse((const char*)xmlString);
	TiXmlElement* RootElement = doc->RootElement();
	TiXmlElement *item = RootElement->FirstChildElement();
	while(item)
	{
		ListItem *listItem=[[ListItem alloc] init];
		const char *id=item->Attribute((const char*)"id");
		const char *name=item->Attribute((const char*)"name");
		listItem.iTitle=[CStringUtil TransformCharToNSString:(char*)name];
		listItem.iSubTitle=[CStringUtil TransformCharToNSString:(char*)id];
		[listView addItme:listItem];
		item = item->NextSiblingElement();
	}
	[listView reloadData];
	delete doc;
}
-(void)dealloc
{
	[listView release];
	[super dealloc];
}


@end
